/**
 * Copyright ©2003~2019年5月23日 szkingdom
 * @author raohj
 * @date 2019年5月23日
 * @file RJMSP2PClient.java
 * @comment : please input your comment to this file
 * @version : input version
 * @modify:
 * 		1、 2019年5月23日 由 raohj 新建文件
 */
package com.ccnu.demojava.mq.jms.p2p;

import javax.jms.*;
import javax.naming.InitialContext;

/**
 * @author raohj
 * @date 2019年5月23日
 * @version 
 * @comment to add your comment
 */
public class RJMSReceiver {
    public static void main(String[] args) throws Exception
    {
       // get the initial context
       InitialContext context = new InitialContext();
                                                                           
      // lookup the queue object
       Queue queue = (Queue) context.lookup("queue/queue0");
                                                                           
       // lookup the queue connection factory
       QueueConnectionFactory conFactory = (QueueConnectionFactory) context.lookup ("queue/connectionFactory");
                                                                           
       // create a queue connection
       QueueConnection queConn = conFactory.createQueueConnection();
                                                                           
       // create a queue session
       QueueSession queSession = queConn.createQueueSession(false,  
       Session.AUTO_ACKNOWLEDGE);
 
       // create a queue receiver
       QueueReceiver queReceiver = queSession.createReceiver(queue);
                                                                           
       // start the connection
       queConn.start();
                                                                           
       // receive a message
       TextMessage message = (TextMessage) queReceiver.receive();
                                                                           
       // print the message
       System.out.println("Message Received: " + message.getText());
                                                                           
       // close the queue connection
       queConn.close();
    }
}
